package com.example.ck.controller;

import com.example.ck.entity.Message;
import com.example.ck.service.MessageService;
import com.example.ck.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 审核消息通知表(Message)表控制层
 *
 * @author makejava
 * @since 2024-04-06 16:03:06
 */
@Slf4j
@RestController
@RequestMapping("message")
@CrossOrigin
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 添加一条新的审核意见
     *
     * @param message
     */
    @PostMapping("/add")
    public ResultVo addMessage(@RequestBody Message message) {
        Message message1 = messageService.addMessage(message);
        return new ResultVo("添加成功", true, message1);
    }

    /**
     * 根据项目id获取指定的评论信息
     *
     * @param projectId
     */
    @GetMapping("/getByProjectId")
    public ResultVo getMessageByProjectId(@RequestParam Integer projectId) {
        List<Message> messages = messageService.getMessageByProjectId(projectId);
        if (messages != null) {
            return new ResultVo("获取成功", true, messages);
        } else {
            return new ResultVo(201, "获取失败", false);
        }
    }

    /**
     * 根据项目id和专家名称查询评审记录
     */
    @GetMapping("/getByProjectIdAndName")
    public ResultVo getMessageByProjectIdAndName(@RequestParam Integer projectId, @RequestParam String name) {
        Message message = messageService.getMessageByProjectIdAndName(projectId, name);
        if (message != null) {
            return new ResultVo("获取成功", true, message);
        } else {
            return new ResultVo(200, "暂无数据", false);
        }
    }
}

